<!doctype html>
<html class="no-js">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="description" content="">
    <meta name="keywords" content="">
    <meta name="viewport"
          content="width=device-width, initial-scale=1">
    <title>文章编辑</title>

    <!-- Set render engine for 360 browser -->
    <meta name="renderer" content="webkit">

    <!-- No Baidu Siteapp-->
    <meta http-equiv="Cache-Control" content="no-siteapp"/>

    <link rel="icon" type="image/png" href="../assets/i/favicon.png">

    <!-- Add to homescreen for Chrome on Android -->
    <meta name="mobile-web-app-capable" content="yes">
    <link rel="icon" sizes="192x192" href="../assets/i/app-icon72x72@2x.png">

    <!-- Add to homescreen for Safari on iOS -->
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-title" content="Amaze UI"/>
    <link rel="apple-touch-icon-precomposed" href="../assets/i/app-icon72x72@2x.png">

    <!-- Tile icon for Win8 (144x144 + tile color) -->
    <meta name="msapplication-TileImage" content="assets/i/app-icon72x72@2x.png">
    <meta name="msapplication-TileColor" content="#0e90d2">

    <link rel="stylesheet" href="../assets/css/amazeui.min.css">
    <link rel="stylesheet" href="../assets/css/app.css">

    <!--在这里编写你的代码-->

    <!--[if (gte IE 9)|!(IE)]><!-->
    <script src="../js/jquery2.js"></script>
    <!--<![endif]-->
    <!--[if lte IE 8 ]>
    <script src="http://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script>
    <script src="http://cdn.staticfile.org/modernizr/2.8.3/modernizr.js"></script>
    <script src="../assets/js/amazeui.ie8polyfill.min.js"></script>
    <![endif]-->
    <script src="../assets/js/amazeui.min.js"></script>
    <script src="../js/vue.js"></script>
    <!--    弹框-->
    <link rel="stylesheet" type="text/css" href="../swal/sweetalert2.min.css">
    <script src="../swal/sweetalert2.min.js"></script>
    <!-- for IE support -->
    <script src="../swal/promise.min.js"></script>
    <!--    <script src="../js/options.js"></script>-->

    <!-- 富文本   -->
    <script src="./editor/release/wangEditor.js"></script>
    <!--    <link rel="stylesheet" type="text/css" href="./editor/release/wangEditor.min.css">-->
</head>

<style>
    body {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }

    /*.lhl-box-3 li{*/
    /*    padding: 10px;*/
    /*}*/
    .lhl-card-h1 {
        margin: 10px;
        font-size: 30px;
        color: #000;
    }

    #lhl-right {
        margin: 0px;
        padding: 30px;
        background: #ecf0f1;
        min-height: 1200px;
    }

    #lhl-head {
        margin: 0px;
    }

    #lhl-card {
        padding: 0px 80px 0px 80px;
    }

    #lhl-card li {
        /*padding: 0px 80px 0px 80px;*/
    }

    .lhl-echar {
        padding: 0px 80px 0px 80px;
    }

    .lhl-echar-card {
    }

    .lhl-nomargin {
        margin: 0px;
    }

    .lhl-list {
        padding-top: 10px;
    }

    .lhl-list h3 {
        margin: 0px;
        /*font-weight: bold;*/
    }

    .am-nav-header {
        border-left: 3px solid #3bb4f2;

    }

    .am-nav > li + .am-nav-header {
        margin-top: 0px;
    }

    .lhl-alert {
        margin: 5px 0px 5px 0px;
    }
</style>

<body>
<div id="app">
    <!-- 头部区域开始 -->
    <header class="am-topbar am-topbar-inverse" id="lhl-head">
        <h1 class="am-topbar-brand">
            <a href="#">Tweet 后台管理</a>
        </h1>

        <button class="am-topbar-btn am-topbar-toggle am-btn am-btn-sm am-btn-success am-show-sm-only"
                data-am-collapse="{target: '#doc-topbar-collapse'}"><span class="am-sr-only">导航切换</span> <span
                class="am-icon-bars"></span></button>

        <div class="am-collapse am-topbar-collapse" id="doc-topbar-collapse">

            <div class="am-topbar-right">
                <div class="am-dropdown" data-am-dropdown="{boundary: '.am-topbar'}">
                    <button class="am-btn am-btn-secondary am-topbar-btn am-btn-sm am-dropdown-toggle"
                            data-am-dropdown-toggle>用户信息 <span class="am-icon-caret-down"></span></button>
                    <ul class="am-dropdown-content">
                        <li><a href="#">用户名:{{UserName}}</a></li>
                        <li><a href="#">修改密码</a></li>
                    </ul>
                </div>
            </div>

            <div class="am-topbar-right">
                <button class="am-btn am-btn-primary am-topbar-btn am-btn-sm" @click="userLogin">管理员登录</button>
            </div>
        </div>
    </header>
    <!-- 头部区域结束 -->
    <!-- 数据化信息开始-->
    <div class="am-g lhl-min-height">
        <div class="am-u-lg-2">
            <ul class="am-nav lhl-list">
                <li><a href="./data.html">首页</a></li>
                <li class="am-nav-divider"></li>
                <li><a href="./data.html">数据展示</a></li>
                <li><a href="./user.html">用户管理</a></li>
                <li><a href="./tweet.html">推文管理</a></li>
                <li><a href="./change.html">账户管理</a></li>
                <li class="am-nav-header">文章管理</li>
                <li><a href="./head.html">推广管理</a></li>
            </ul>
        </div>
        <div class="am-u-lg-10" id="lhl-right">
            <h1>文章管理</h1>
            <div class="am-u-lg-8">
                <table class="am-table am-table-bordered am-table-radius"
                       style="background-color:#fff; padding-top: 10px;">
                    <tr>
                        <td>
                            <div class="am-form-inline">
                                <div class="am-form-group">
                                    <label class="am-form-label">文章标题</label>
                                    <input type="text" class="am-form-field" placeholder="输入文章标题..." width="300px"
                                           v-model="title">
                                </div>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div id="lhl-editor"></div>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <button class="am-btn am-btn-primary" @click="sumbitEditor">提交文章</button>
                        </td>
                    </tr>
                    <tr>
                        <td v-show="showRect">
                            <h3 class="am-text-success lhl-alert" v-show="postResult">提交成功 <a v-bind:href="url">预览(如果404错误请稍等30s)</a>
                            </h3>
                            <h3 class="am-text-danger lhl-alert" v-show="!postResult">提交失败</h3>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="am-u-lg-4">
                <table class="am-table am-table-bordered am-table-radius"
                       style="background-color:#fff; padding-top: 10px;">
                    <tr>
                        <td>
                            <a href="#" class="am-link-muted">文章列表</a>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <ul class="am-list am-list-static">
                                <li v-for="(item,key) in editorList">
                                    {{item.title}}
                                    <span><a v-bind:href="'./achtml/'+item.fileurl" target="_blank">预览</a>
                                    <i class="am-icon-eye" v-show="item.show" @click="editorShowSet(key)"></i>
                                    <i class="am-icon-eye-slash" v-show="!item.show" @click="editorShowSet(key)"></i></span>
                                </li>
                            </ul>
                            <ul class="am-pagination">
                                <li><a href="#" @click="queryEditorList(-1)">&laquo; 上一页</a></li>
                                <li><a href="#" @click="queryEditorList(1)">下一页 &raquo;</a></li>
                            </ul>
                        </td>
                    </tr>
                </table>
            </div>

        </div>

    </div>
    <!-- 数据化信息结束-->
</div>


<script type="text/javascript">

    var app = new Vue({
        el: "#app",
        data: {
            UserPassword: '',
            UserName: '',
            editor2: null,
            title: '',
            url: '#',
            showRect: false,
            postResult: true,
            editorList: [],
            page: 0,

        },
        methods: {
            inputPwd: function () {
                swal({
                    title: '输入密码',
                    input: 'password',
                    inputAttributes: {
                        'maxlength': 30,
                        'autocapitalize': 'off',
                        'autocorrect': 'off'
                    }
                }).then(function (result) {
                    app.UserPassword = result;
                    $.post('../manager', {
                        type: 'login',
                        username: app.UserName,
                        password: app.UserPassword
                    }, function (response) {
                        if (response == "success") {
                            swal(
                                '您好！' + app.UserName,
                                '欢迎登录后台管理，请为所欲为吧!',
                                'success'
                            );
                        } else {
                            swal(
                                '登陆失败！',
                                '抱歉您登录不成功，没办法为所欲为!',
                                'error'
                            )
                        }
                    });
                })
            },
            userLogin: function () {
                //登录
                swal({
                    title: '输入登录账号',
                    input: 'text',
                    showCancelButton: true,
                    inputValidator: function (value) {
                        return new Promise(function (resolve, reject) {
                            if (value) {
                                resolve();
                            } else {
                                reject('请填写账号');
                            }
                        });
                    }
                }).then(function (result) {
                    // 输入用户完成
                    app.UserName = result;
                    app.inputPwd();
                })
            },
            sumbitEditor: function () {
                //文章提交
                var _this = this;
                this.showRect = false;
                if (this.editor2.txt.text().length > 0 && this.title.length > 0) {
                    $.post('../manager', {
                        type: 'editor.add',
                        title: this.title,
                        html: this.editor2.txt.html(),
                    }, function (response) {
                        if (response != "") {
                            response = JSON.parse(response);
                            _this.showRect = true;
                            _this.postResult = response.result;
                            _this.url = response.url;
                        }
                    });
                } else {
                    _this.showRect = true;
                    _this.postResult = false;
                }
            },
            queryEditorList: function (bit) {
                //查询文章列表

                if (this.page + bit < 0) {
                    return false;

                } else {
                    this.page += bit;
                }
                $.post('../manager', {
                    type: 'editor.show',
                    page: this.page,
                }, function (response) {
                    // console.log(response);
                    if (response != "") {
                        response = JSON.parse(response);
                        Vue.set(app, "editorList", response.result);
                    }
                });
            },
            editorShowSet:function (key) {
                //控制显示
                // this.editorList[key].show=!this.editorList[key].show;
                $.post('../manager',{
                    type:'editor.setshow',
                    id:this.editorList[key].fileid,
                    show:!this.editorList[key].show,
                },function (result) {
                    if (result!=""){
                        result=JSON.parse(result)
                        if (result.result){
                            Vue.set(app.editorList[key],'show',!app.editorList[key].show);
                        }
                    }
                })
            }

        },
        created: function () {
            this.queryEditorList(0);
        },
        mounted: function () {
            var E = window.wangEditor;
            this.editor2 = new E('#lhl-editor');
            this.editor2.create();
        }
    });
</script>
<!--<script src="../js/options.js"></script>-->
<!--<script src="../js/manager_js.js"></script>-->
</body>
</html>